package com.cuit.xsc.weishare.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cuit.xsc.weishare.R;
import com.cuit.xsc.weishare.model.DirectMessage;
import com.cuit.xsc.weishare.util.LogUtil;
import com.cuit.xsc.weishare.util.TextUtil;
import com.cuit.xsc.weishare.widget.RemoteCacheImageView;

public class PrivateMsgConversationAdapter extends ArrayListAdapter<DirectMessage>
{

	private Context context;
	
	public PrivateMsgConversationAdapter(Activity context)
	{
		super(context);
		this.context = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
//		Holder holder = null;
		View view = null;
		DirectMessage directMessage = mList.get(position);
		if (directMessage != null)
		{
			int type = directMessage.getType();
			String head = null;
			String text = null;
			
			if (type == DirectMessage.RECV)
			{
				view = LayoutInflater.from(context).inflate(R.layout.list_say_he_item, null);
			}
			else if (type == DirectMessage.SEND)
			{
				view = LayoutInflater.from(context).inflate(R.layout.list_say_me_item, null);
			}
			//LogUtil.i(this, "view="+view);
//			
//			holder = new Holder();
			RemoteCacheImageView messagegedetail_rov_icon = (RemoteCacheImageView) view.findViewById(R.id.messagegedetail_rov_icon);
			TextView messagedetail_row_text = (TextView) view.findViewById(R.id.messagedetail_row_text);
			TextView messagedetail_row_time = (TextView) view.findViewById(R.id.messagedetail_row_time);
			
			//convertView.setTag(holder);
			//LogUtil.i(this, directMessage.getName()+"_"+directMessage.getHead()+"_"+directMessage.getTime()+"_"+directMessage.getText());

			//LogUtil.i(this, "mListView="+mListView);
			
			
			messagegedetail_rov_icon.setImageUrl(directMessage.getHead(), position, mListView);
		    messagedetail_row_text.setText(directMessage.getText());
			messagedetail_row_time.setText(TextUtil.formatDate(directMessage.getTime()));
		}
		//LogUtil.i(this, "view="+view);
		return view;
	}
	
	public class Holder
	{
		RemoteCacheImageView messagegedetail_rov_icon;
		TextView messagedetail_row_text;
		TextView messagedetail_row_time;

	}

}
